package errMsg

import "errors"

// 错误分类
const (
	SYSTEM_ERROR = (iota + 1) * 1000
	USER_ERROR
	CATEGORY_ERROR
	ARTICLE_ERROR
)

const (
	SUCCESS = SYSTEM_ERROR + iota
	ERROR
	FAIL
	DB_ERROR
	DB_OPTION_FAIL
	PARAM_ERROR
	TOKEN_NOT_EXIST
	TOKEN_WRONG
	TOKEN_EXPIRE
	TOKEN_TYPE_WRONG
	OSS_UPLOAD_FAIL
)

var (
	UserNotFount = errors.New("2")
)

// 用户模块错误
const (
	ERROR_USERNAME_USED = USER_ERROR + iota
	ERROR_PASSWORD_WRONG
	ERROR_USER_NOT_EXIST
)

const (
	ERROR_CATEGORY_USED = CATEGORY_ERROR + iota
	ERROR_CATEGORY_NOT_EXIST
)

const (
	ERROR_Article_NOT_EXIST = ARTICLE_ERROR + iota
)

type Code int

var errMsg = map[Code]string{
	SUCCESS:              "ok",
	ERROR:                "fail",
	DB_ERROR:             "数据库操作错误",
	DB_OPTION_FAIL:       "操作失败",
	PARAM_ERROR:          "参数异常",
	ERROR_USERNAME_USED:  "用户名已存在",
	ERROR_PASSWORD_WRONG: "密码错误",
	ERROR_USER_NOT_EXIST: "用户不存在",

	ERROR_CATEGORY_USED:      "分类已存在",
	ERROR_CATEGORY_NOT_EXIST: "分类不存在",

	TOKEN_NOT_EXIST:  "token不存在",
	TOKEN_EXPIRE:     "token过期",
	TOKEN_TYPE_WRONG: "token格式错误",
	TOKEN_WRONG:      "token错误",

	OSS_UPLOAD_FAIL: "上传失败",
}

func (c *Code) GetMsg() string {
	if v, ok := errMsg[*c]; ok {
		return v
	}
	return "未知错误"
}
